package com.keyidea.jfxui.core.server.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;

import java.util.Map;

public class CustomUtil {

    /**
     * 获取redis的统一格式的key
     *
     * @param satellite 卫星
     * @param waveNo    波束
     * @param fpVal     频点
     * @return 统一格式的key
     */
    public static String getRedisKey(String satellite, String waveNo, String fpVal) {
        return String.format("%s:%s:%s", satellite, waveNo, fpVal);
    }

    /**
     * 将map转为obj
     */
    public static <T> T map2obj(Map obj, Class<T> clazz) {
        return JSONObject.parseObject(JSON.toJSONString(obj), clazz);
    }

    /**
     * obj转map
     */
    public static <T> T obj2map(Object obj, TypeReference<T> reference) {
        return JSONObject.parseObject(JSON.toJSONString(obj), reference);
    }
}
